package com.maxmlr.music.user.service.transfer;

import com.maxmlr.music.common.util.DateUtil;
import com.maxmlr.music.song.entity.Song;
import com.maxmlr.music.system.entity.Files;
import com.maxmlr.music.user.entity.UserInfo;
import com.maxmlr.music.user.entity.UserSongEstimate;
import com.maxmlr.music.user.param.UserSongEstimateInParam;
import com.maxmlr.music.user.param.UserSongEstimateOutParam;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;
import java.util.Objects;

/**
 * @ClassName SongEstimateTransfer
 * @Description TODO
 * @Author maxiao
 * @Date 2020/6/8 下午4:44
 * @Version V1.0
 */
@Component
public class UserSongEstimateTransfer {
    public UserSongEstimate po2UserSongEstimate(UserSongEstimateInParam inParam, UserInfo userInfo) {
        Date date = DateUtil.getDate();
        UserSongEstimate songEstimate = new UserSongEstimate();
        songEstimate.setUserId(userInfo.getId());
        songEstimate.setSongId(inParam.getSongId());
        songEstimate.setEstimateInfo(inParam.getEstimateInfo());
        songEstimate.setCreateTime(date);
        songEstimate.setUpdateTime(date);
        return songEstimate;
    }

    public UserSongEstimateOutParam po2UserSongEstimateOutParam(UserSongEstimate songEstimate, UserInfo userInfo, Song song, Files files) {
        UserSongEstimateOutParam userSongEstimateOutParam = new UserSongEstimateOutParam();
        userSongEstimateOutParam.setId(songEstimate.getId());
        userSongEstimateOutParam.setSongId(songEstimate.getSongId());
        userSongEstimateOutParam.setSongName(song.getSongName());
        userSongEstimateOutParam.setUserId(songEstimate.getUserId());
        userSongEstimateOutParam.setUserHeadImg(files.getUrl());
        userSongEstimateOutParam.setUserName(userInfo.getUserName());
        userSongEstimateOutParam.setEstimateInfo(songEstimate.getEstimateInfo());
        return userSongEstimateOutParam;
    }

    public void fullUserInfo(UserSongEstimateOutParam outParam, Map<Integer, UserInfo> userMap, Map<Integer, String> headImgMap) {
        UserInfo userInfo = userMap.get(outParam.getUserId());
        if (Objects.nonNull(userInfo)) {
            outParam.setUserName(userInfo.getUserName());
            outParam.setUserHeadImg(headImgMap.get(userInfo.getHeadImgId()));
        }
    }
}
